package com.sxpi.zixun.controller.category;

import com.sxpi.zixun.bo.CategoryBo;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.Category;
import com.sxpi.zixun.service.category.ICategoryService;
import com.sxpi.zixun.vo.CategoryVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/1 9:31
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="文章分类管理",tabname="kss_category")
public class CategoryController extends BaseController {

    private final ICategoryService categoryService;

    /**
     * 查询管理分类
     * @return
     */
    @PostMapping("/category/tree")
    @PugDoc(name="查询管理分类")
    public List<CategoryBo> findCategoryTree(@RequestParam("keyword") String keyword){
        return categoryService.findCategoryTree(keyword);
    }

    /**
     * 保存和修改文章分类管理
     * @param category
     * @return
     */
    @PostMapping("/category/saveupdate")
    @PugDoc(name="保存和修改文章分类管理")
    public CategoryBo saveUpdateCategory(@RequestBody Category category) {
        return categoryService.saveUpdateCategory(category);
    }

    /**
     * 根据文章分类管理id删除文章分类管理
     * @param id
     * @return
     */
    @PostMapping("/category/delete/{id}")
    @PugDoc(name="根据文章分类管理id删除文章分类管理")
    public int deleteCategoryById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id,ResultStatusEnum.ID_NOT_EMPTY);
        return categoryService.deleteCategoryById(new Long(id));
    }

    /**
     * 根据文章分类管理ids批量删除文章分类管理
     * @param categoryVo
     * @return
     */
    @PostMapping("/category/delBatch")
    @PugDoc(name="根据文章分类管理ids批量删除文章分类管理")
    public boolean deleteCategoryBatch(@RequestBody CategoryVo categoryVo) {
        Vsserts.isEmptyEx(categoryVo.getBatchIds(),ResultStatusEnum.ID_NOT_EMPTY);
        return categoryService.deleteBatchCategory(categoryVo.getBatchIds());
    }

}
